// 页面加载完成后执相应方法
$(function () {
    $("#topBtn").click(setTop);
    $("#digestBtn").click(setDigest);
    $("#deleteBtn").click(setDelete);
});

// 发送点赞请求
function like(btn,entityType,entityId,entityUserId,postId){
    $.post(
        CONTENT_PATH + "/like/praise",
        {"entityType":entityType,"entityId":entityId,"entityUserId":entityUserId,"postId":postId},
        function (data) {
            data = $.parseJSON(data);
            if(data.code == 0){
                $(btn).children("i").text(data.likeCount);
                $(btn).children("b").text(data.likeStatus==1?'已赞':'赞');
            } else {
                alert(data.msg);
            }
        }
    )
}

// 置顶
function setTop(){
    $.post(
        CONTENT_PATH + "/discuss/top",
        {"postId":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0){
                $("#topBtn").attr("disabled","disabled");
                alert(data.msg);
            } else {
                alert("置顶失败!");
            }
        }
    )
}

// 加精
function setDigest(){
    $.post(
        CONTENT_PATH + "/discuss/digest",
        {"postId":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0){
                $("#digestBtn").attr("disabled","disabled");
                alert(data.msg);
            } else {
                alert("加精失败!");
            }
        }
    )
}

// 删除
function setDelete(){
    $.post(
        CONTENT_PATH + "/discuss/delete",
        {"postId":$("#postId").val()},
        function (data) {
            data = $.parseJSON(data);
            if(data.code === 0){
                location.href = CONTENT_PATH + "/index";
            } else {
                alert("删除失败!");
            }
        }
    )
}

